export default {
    formatMoney(value) {
        if (!value) return '0.00'
        if (value > 100000000 || value < -100000000) {
            return Number(value / 100000000).toFixed(2) + '亿'
        } else if (value > 10000 || value < -10000) {
            return Number(value / 10000).toFixed(2) + "万"
        } else {
            return Number(value).toFixed(2) + '元'
        }
    },

    // 计算两数相加
    sum(arr) {
        return arr.reduce((prev, curr) => {
            return prev + curr;
        });
    },

    formatMoneyTwo(value) {
        if (!value) return '0.00'
        return Number(value / 10000).toFixed(2)
    },

    formatTime(time) {
        let date = new Date(time)
        let [year, month, day, hour, minute, second] = [
            date.getFullYear(),
            date.getMonth() + 1,
            date.getDate(),
            date.getHours(),
            date.getMinutes(),
            date.getSeconds()
        ]
        if (month < 10) {
            month = '0' + month
        }
        if (day < 10) {
            day = '0' + day
        }
        return year + '-' + month + '-' + day + " " + hour + ':' + minute + ":" + second
    },

    formatTimeMonth(time) {
        let date = new Date(time)
        let [year, month] = [
            date.getFullYear(),
            date.getMonth() + 1
        ]
        if (month < 10) {
            month = '0' + month
        }
        return year + '-' + month
    },
}